<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// 检查登录状态
			this.checkLoginStatus()
		},
		onShow: function() {
			console.log('App Show')
			// 检查登录状态
			this.checkLoginStatus()
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			checkLoginStatus() {
				// 获取当前页面路径
				const pages = getCurrentPages()
				const currentPage = pages[pages.length - 1]
				const currentPath = currentPage ? currentPage.route : ''
				
				// 如果当前不在登录页，且没有token，则跳转到登录页
				if (currentPath !== 'pages/login/login') {
					const token = uni.getStorageSync('token')
					if (!token) {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}
				}
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	page {
		background-color: #f6f6f6;
	}
</style>
